package com.it.whitejotterapi.service.impl;

import com.it.whitejotterapi.service.SendMessage;
import com.it.whitejotterapi.tools.HttpClientUtil;
import com.it.whitejotterapi.tools.JsonResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;

/**
 * @Author: 羡羡
 * @Date: 2022/05/29/11:08
 */
@Service
public class SendMessageImpl implements SendMessage {

    /**
     * 用户名
     */
    @Value("${message.uid}")
    private String uid;

    /**
     * 秘钥
     */
    @Value("${message.key}")
    private String key;

    /**
     * 发送短信
     * @param iphone 发送的电话
     * @param context 发送的内容
     * @return
     */
    @Override
    public JsonResult sendmes(String iphone, String context) throws UnsupportedEncodingException {
        HttpClientUtil client=HttpClientUtil.getInstance();
        //转码
        String zuid=new String(uid.getBytes("iso-8859-1"),"utf-8");
        int result = client.sendMsgUtf8(zuid,key,context,iphone);
        if(result>0){
            return new JsonResult(200,"发送成功！");
        }else{
            return new JsonResult(500,client.getErrorMsg(result));
        }
    }
}
